<html>
	<head>
		<title>随机密码生成</title>
	</head>
	<body>
		<button onclick="javascript:xdst()" style="background-color:cadetblue;">数字，字母，特殊符号[8+]</button>
		<button onclick="javascript:s()" style="background-color:aliceblue">仅数字[3+]</button>
		<button onclick="javascript:xds()" style="background-color:skyblue" ;>数字+字母[6+]</button>
		<input type="text" id="inputId" placeholder="请输入要生成的密码长度!"/>
		<div id="showId" style="padding:2px;width: 100px;margin: 2px;"></div>
		<script type="text/javascript">
			////////////////////////////////////////////////////////////////////////////////////////
			var signArray_xdst = [ //去掉Il1,0O,<,支付密码4、//76
				["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
				["n", "o", "p", "q", "r", "s", "t", "u", "v", "w"],
				["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"],
				["N", "P", "Q", "R", "S", "T", "U", "V", "W", "X"],
				["k", "m", "x", "y", "z", "L", "M", "Y", "Z"],
				["2", "3", "4", "5", "6", "7", "8", "9"],
				["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"],
				["~", "_", "+", "{", "}", ":", ">", "?", "|"]
			];

			function xdst() {
				var pwd = [];
				//随机生成密码长度8-16
				//var len = randomNum(8,16);
				var len = document.getElementById('inputId').value;
				console.log('len]'+len);
				//循环密码长度
				for (var i = 0; i < signArray_xdst.length; i++) {
					var tmpArray = signArray_xdst[i];
					var signIndex = Math.floor(Math.random() * tmpArray.length);
					pwd.push(tmpArray[signIndex]);
				}
				for (var i = 0; i < len - signArray_xdst.length; i++) {
					var indexNei = Math.floor(Math.random() * signArray_xdst.length);
					var tmpArray = signArray_xdst[indexNei];
					var signIndex = Math.floor(Math.random() * tmpArray.length);
					pwd.push(tmpArray[signIndex]);
				}
				pwd.shuffle();
				document.getElementById("showId").innerHTML = pwd.join("");
			}
			//////////////////////////////////////////////////////////////////////////////////////////////
			var signArray_s = [
				["0", "1", "2"],
				["3", "5", "6"],
				["7", "8", "9"]
			];

			function s() {
				var pwd = [];
				//随机生成密码长度8-16
				//var len = randomNum(8,16);
				var len = document.getElementById('inputId').value;
				//循环密码长度
				for (var i = 0; i < signArray_s.length; i++) {
					var tmpArray = signArray_s[i];
					var aaa = Math.random() * tmpArray.length;
					console.log("aaa]" + aaa);
					var signIndex = Math.floor(aaa); //向下取整正好是同等概率每段数字下标的位置
					console.log("signIndex]" + signIndex)
					pwd.push(tmpArray[signIndex]);
				}
				for (var i = 0; i < len - signArray_s.length; i++) {
					var indexNei = Math.floor(Math.random() * signArray_s.length);
					var tmpArray = signArray_s[indexNei];
					var signIndex = Math.floor(Math.random() * tmpArray.length);
					pwd.push(tmpArray[signIndex]);
				}
				pwd.shuffle();
				document.getElementById("showId").innerHTML = pwd.join("");
			}
			////////////////////////////////////////////////////////////////////////////////////////////
			var signArray_xds = [ //57
				["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
				["n", "o", "p", "q", "r", "s", "t", "u", "v", "w"],
				["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"],
				["N", "P", "Q", "R", "S", "T", "U", "V", "W", "X"],
				["k", "m", "x", "y", "z", "L", "M", "Y", "Z"],
				["2", "3", "4", "5", "6", "7", "8", "9"],
			];

			function xds() {
				var pwd = [];
				//随机生成密码长度8-16
				//var len = randomNum(8,16);
				var len = document.getElementById('inputId').value;
				//循环密码长度
				for (var i = 0; i < signArray_xds.length; i++) {
					var tmpArray = signArray_xds[i];
					var signIndex = Math.floor(Math.random() * tmpArray.length);
					pwd.push(tmpArray[signIndex]);
				}
				for (var i = 0; i < len - signArray_xds.length; i++) {
					var indexNei = Math.floor(Math.random() * signArray_xds.length);
					var tmpArray = signArray_xds[indexNei];
					var signIndex = Math.floor(Math.random() * tmpArray.length);
					pwd.push(tmpArray[signIndex]);
				}
				pwd.shuffle();
				document.getElementById("showId").innerHTML = pwd.join("");
			}
			///////////////////////////////////////////////////////////////////////////////////////////
			function randomNum(min, max) {
				return Math.floor(Math.random() * (max - min + 1) + min);
			}
			Array.prototype.shuffle = function() {
				let arr = this,
					temp,
					length = arr.length;
				for (let i = 0; i < arr.length - 1; i++) {
					let index = Math.floor(Math.random() * (length--));
					temp = arr[index];
					arr[index] = arr[length];
					arr[length] = temp;
				}
				return arr;
			};
		</script>
	</body>
</html>
